using System;
using System.Collections;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;

[ExecuteAlways]
public class EditorLoadAnimation : MonoBehaviour
{
    const string loadPath = "Assets/ShacoFramework/VPlayable/Pro Melee Axe Pack";
    public List<VAnimationClip> animationClips;
    [Button]
    private void ExtractAnimations()
    {
        string[] paths = AssetDatabase.FindAssets("", new[] { loadPath });
        foreach (var p in paths)
        {
            string pa = AssetDatabase.GUIDToAssetPath(p);
            UnityEngine.Object[] o = AssetDatabase.LoadAllAssetsAtPath(pa);

            if (o[2] is AnimationClip ac)
            {
                string savePath = loadPath + $"/{o[0].name}_ani.anim";
                AnimationClip newClip = new AnimationClip();
                newClip.name = o[1].name;
                EditorUtility.CopySerialized(ac, newClip);
                AssetDatabase.CreateAsset(newClip, savePath);
                print($"save files at : {loadPath + $"/{o[1].name}"}");
                if(o[3].name.Contains("Y Bot")) continue;

                AssetDatabase.DeleteAsset(pa);
            }

        }
        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();
    }
    public PlayableDirector director;
    private void Update()
    {
        // director.time += 0.001f;
        // director.Evaluate();
    }

}

[Serializable]
public class VAnimationClip
{
    public string name;
    public AnimationClip clip;
}
